﻿Public Class clsPieChart
    Inherits clsChart

    Private m_dRadius As Single
    Private m_dSpace As Single
    Private m_pCenter As Point

    Public Sub New(ByVal dRadius As Single, ByVal dSpace As Single)
        MyBase.New(CInt(dRadius + dSpace), CInt(dRadius + dSpace))

        m_dRadius = dRadius
        m_dSpace = dSpace

        m_pCenter = New Point((dRadius + dSpace) / 2, (dRadius + dSpace) / 2)
    End Sub

    Public Property Radius As Single
        Get
            Return m_dRadius
        End Get
        Set(ByVal value As Single)
            m_dRadius = value
        End Set
    End Property

    Public Property Space As Single
        Get
            Return m_dSpace
        End Get
        Set(ByVal value As Single)
            m_dSpace = value
        End Set
    End Property

    Protected Overrides Sub Render(ByRef g As System.Drawing.Graphics)
        Dim dTotalValue As Single = 0.0
        Dim dStartAngle As Single = 90.0
        Dim dSweepAngle As Single = 0.0
        Dim dSpaceAngle As Single = 0.0

        Dim pLocationBox As Rectangle = Nothing

        ' Calculate the total value of all entries
        For Each pEntry In m_pGraphEntries.Entries
            dTotalValue += pEntry.Value
        Next

        For Each pEntry In m_pGraphEntries.Entries
            ' TODO: implement the spacing
            dSweepAngle = 360.0 * (pEntry.Value / dTotalValue)
            dSpaceAngle = (dStartAngle + dSweepAngle) / 2



            g.FillPie(New SolidBrush(GetNextColor), CSng(0.0), CSng(0.0), m_dRadius, m_dRadius, dStartAngle, dSweepAngle)
            dStartAngle += dSweepAngle
        Next
    End Sub
End Class
